// 接口请求函数 返回一个promise对象
import instance from './request'

// 登录
export const reqLogin = (username, pwd) => {
    return instance({
        method: 'post',
        url: '/login',
        data: {
            username,
            pwd
        }
    })
}

// 获取登录用户信息
export const reqUserInfo = () => {
    return instance({
        method: 'get',
        url: '/user/info'
    })
}

//退出登录
export const reqLogout = () => {
    return instance({
        method: 'get',
        url: '/logout'
    })
}

// 获取用户列表
export const reqUserList = (page, limit) => {
    return instance({
        method: 'get',
        url: `/user/${page}/${limit}`
    })
}

// 获取单个用户
export const reqUser = (id) => {
    return instance({
        method: 'get',
        url: '/user',
        params: {
            id
        }
    })
}

// 添加用户
export const reqAddUser = (user) => {
    return instance({
        method: 'post',
        url: '/user',
        data: user
    })
}

// 更新用户
export const reqUpdateUser = (formData) => {
    return instance({
        method: 'put',
        url: '/user',
        data: formData
    })
}

// 删除用户
export const reqDeleteUser = (id) => {
    return instance({
        method: 'delete',
        url: `/user/${id}`
    })
}
